package com.yanqu.road.utils.http;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

public class HttpResult {

    private int code = 200;

    private String msg = "成功";

    private JSONObject data = new JSONObject();

    public static HttpResult successCode(int code) {
        HttpResult result = new HttpResult();
        result.setCode(code);
        return result;
    }

    public static HttpResult failCode(int code, String msg) {
        HttpResult result = new HttpResult();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }

    public static HttpResult failMsg(String msg) {
        HttpResult result = new HttpResult();
        result.setCode(-1);
        result.setMsg(msg);
        return result;
    }

    public static HttpResult defaultInstance() {
        return new HttpResult();
    }

    public int getCode() {
        return code;
    }

    public HttpResult setCode(int code) {
        this.code = code;
        return this;
    }

    public String getMsg() {
        return msg;
    }

    public HttpResult setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public JSONObject getData() {
        return data;
    }

    public void setData(JSONObject data) {
        this.data = data;
    }

    public String toJsonString() {
        return JSON.toJSONString(this);
    }
}
